<template>
    <div class="login-box">
        <div class="login-full-box"></div>
        <div class="slot-box">
            <div class="form-box">
                <p class="login-tit">admin-web</p>
                <el-form :model="ruleForm" :rules="rules" ref="ruleForm">
                    <el-form-item prop="name">
                        <el-input v-model="ruleForm.name" placeholder="请输入用户名" clearable>
                            <i slot="prefix" class="el-icon-user-solid"></i>
                        </el-input>
                    </el-form-item>
                    <el-form-item prop="password">
                        <el-input v-model="ruleForm.password" placeholder="请输入密码" type="password" show-password clearable>
                            <i slot="prefix" class="el-icon-lock"></i>
                        </el-input>
                    </el-form-item>
                    <el-form-item prop="codeNum">
                        <div class="code-box">
                            <el-input v-model="ruleForm.codeNum" placeholder="验证码" clearable>
                            </el-input>
                            <img :src="captchaPath" class="code-img" @click="getCaptcha()" />
                        </div>
                    </el-form-item>
                    <p class="accmount" @click="dialogVisible = true">获取体验账号</p>
                    <el-form-item>
                        <el-button type="primary" @click="submitForm('ruleForm')" class="loginbtn">登录</el-button>
                    </el-form-item>
                </el-form>
            </div>
        </div>
        <!-- 获取体验账号弹框 -->
        <el-dialog title="公众号二维码" :visible.sync="dialogVisible" :show-close="false" :center="true" width="30%">
            <div style="text-align: center">
                <span class="font-title-large"><span class="color-main font-extra-large">关注公众号</span>回复<span class="color-main font-extra-large">体验</span>获取体验账号</span>
                <br>
                <img src="../../assets/img/qcode.jpg" width="160" height="160" style="margin-top: 10px">
            </div>
            <span slot="footer" class="dialog-footer">
                <el-button type="primary" @click="dialogVisible = false">确定</el-button>
            </span>
        </el-dialog>
    </div>
</template>
<script>
import { timeStamp } from "../../utils/date";
import { randomStr } from "../../utils/tools";
import baseUrl from "../../utils/api/base";
export default {
    data() {
        return {
            ruleForm: {
                name: "",
                password: "",
                codeNum: ''
            },
            dialogVisible: false,
            captchaPath: "",
            rules: {
                name: [
                    { required: true, message: '请输入用户名', trigger: 'blur' }
                ],
                password: [
                    { required: true, message: '请输入密码', trigger: 'blur' }
                ],
                codeNum: [
                    // { required: true, message: '请输入验证码', trigger: 'blur' }
                ]
            },
            randKey: ""
        }
    },
    created() {

    },
    mounted() {
        this.getCaptcha();
    },
    methods: {
        getCaptcha() {
            this.randKey = timeStamp() + randomStr();
            this.captchaPath = baseUrl.sq + '/open/code?randomKey=' + this.randKey;
        },
        submitForm(formName) {
            this.$refs[formName].validate((valid) => {
                if (valid) {
                    this.$api.callName.login({
                        code: this.ruleForm.codeNum,
                        password: this.ruleForm.password,
                        randomKey: this.randKey,
                        username: this.ruleForm.name
                    }).then(res => {
                        if (res.data.code === 0) {
                            sessionStorage.setItem('userInfo', JSON.stringify(res.data.data.principal.loginUser.user));
                            this.$message.success(this.$mesTip.loginTxt);
                            this.$router.push({
                                name: "home"
                            });
                            sessionStorage.setItem('gitssessionid', res.headers.gitssessionid)
                        } else {
                            this.getCaptcha()
                        }
                    })
                }
            });

        },
    },
}
</script>
<style lang="scss">
.login-full-box {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    height: 100%;
    -webkit-filter: blur(5px); /* Chrome, Opera */
    -moz-filter: blur(5px);
    -ms-filter: blur(5px);
    filter: blur(3px);
    background: url("~@/assets/img/login2.jpg");
    background-size: 100% 100%;
    // animation: animate-cloud 20s linear infinite;
}
.font-extra-large{
    font-size: 16px;
    color: #409eff;
}
.slot-box {
    display: flex;
    align-items: center;
    justify-content: center;
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
}
.login-tit {
    font-size: 18px;
    color: #409eff;
    font-weight: bold;
    text-align: center;
}
.form-box {
    width: 260px;
    padding: 10px 20px;
    background: #ffffff;
    border-radius: 6px;
    box-shadow: 0 7px 25px rgba(0, 0, 0, 0.08);
    .el-form-item {
        margin-bottom: 22px;
    }
    .el-icon-user-solid {
        font-size: 18px;
        color: #409eff;
    }
    .el-icon-lock {
        font-size: 18px;
        color: #409eff;
    }
    .loginbtn {
        width: 100%;
    }
    .accmount {
        margin-bottom: 5px;
        text-align: right;
        font-size: 13px;
        color: #666666;
        cursor: pointer;
    }
    .code-img {
        margin-left: 5px;
        width: 120px;
        height: 36px;
    }
    .code-box {
        display: flex;
        align-items: center;
    }
}
@keyframes animate-cloud {
    0% {
        background-position: 600px 100%;
    }
    100% {
        background-position: 0 100%;
    }
}
</style>